package com.ruoyi.web.controller.oper;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.oper.domain.OperPerson;
import com.ruoyi.oper.service.IOperPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/oper/person")
public class OperPersonController extends BaseController {
    @Autowired
    private IOperPersonService operPersonService;

    @GetMapping("/check")
    public OperPerson checkOperPerson(OperPerson operPerson, HttpServletRequest request){
        List<OperPerson> operPersonList = operPersonService.selectOperPersonList(operPerson);
        if(operPersonList != null && operPersonList.size() > 0){
            OperPerson operPerson1 = operPersonList.get(0);
            return operPerson1;
        }else{
            return null;
        }
    }

    @GetMapping("/insert")
    public int insert(OperPerson operPerson){
        return operPersonService.insertOperPerson(operPerson);
    }
//    @RequestMapping("/upload")
//    @ResponseBody
    @PostMapping("/upload")
    public Map<String, String> upload(@RequestParam("uploadfile") MultipartFile file) throws IOException {
        Map<String, String> map = new HashMap<>();
        String newPath = FileUploadUtils.upload("D:/profile/news/",file);
        map.put("src",newPath);
        return map;
    }
}
